# coding: UTF-8
# Filename : medical_answer_action.py
# Company : imedia
# Author : rose
# -*-coding:utf-8 -*-
from api.common.common import *
from api.common import mysql,log,utils,httputils,const,xml_tpl,err_tpl
from django.shortcuts import render_to_response
import medical_answer_manage

#获取咨询预约列表
def list(request):
    #记录用户脚印(必做动作)
    httputils.footprint(request)
    #通信验证
    if validate(request):
        return validate(request)
    user_id = httputils.post(request, 'user_id')
    cus_id = httputils.post(request, 'cus_id')
    size = httputils.post(request, 'size')
    pagenum = httputils.post(request, 'pagenum')
    if not utils.is_num(user_id): user_id = 0
    if not utils.is_num(cus_id): cus_id = 0
    if not utils.is_num(size): size = 0
    if not utils.is_num(pagenum): pagenum = 0
    ma = medical_answer_manage.get_list(user_id, cus_id, size, pagenum)
    return render_to_response('yiliao/medical_answer/success_list.xml',{'ma':ma}, mimetype="application/xhtml+xml")

#发表咨询预约
def ask(request):
    #记录用户脚印(必做动作)
    httputils.footprint(request)
    #通信验证
    if validate(request):
        return validate(request)
    user_id = httputils.post(request, 'user_id')
    cus_id = httputils.post(request, 'cus_id')
    content = httputils.post(request, 'content')
    reply = httputils.post(request, 'reply')
    if not utils.is_num(user_id): user_id = 0
    if not utils.is_num(cus_id): cus_id = 0
    if not utils.is_num(reply): reply = 0
    
    rst = medical_answer_manage.insert_ask(user_id, cus_id, content, reply)
    if rst:
        success = 1
        msg = '成功'
    else:
        success = 0
        msg = '失败'
    dict_obj = {'success':success, 'msg':msg}
    return render_to_response('yiliao/medical_answer/success_ask.xml',dict_obj, mimetype="application/xhtml+xml")

def get_count(request):
    #记录用户脚印(必做动作)
    httputils.footprint(request)
    #通信验证
    if validate(request):
        return validate(request)
    user_id = httputils.post(request, 'user_id')
    cus_id = httputils.post(request, 'cus_id')
    reply_id = httputils.post(request, 'reply_id')
    if not utils.is_num(user_id): user_id = 0
    if not utils.is_num(cus_id): cus_id = 0
    if not utils.is_num(reply_id): reply_id = 0
    count = medical_answer_manage.get_count(user_id, cus_id, reply_id)
    return render_to_response('yiliao/medical_answer/count.xml',{'count':count}, mimetype="application/xhtml+xml")
    
def delete(request):
    #记录用户脚印(必做动作)
    httputils.footprint(request)
    #通信验证
    if validate(request):
        return validate(request)
    id = httputils.post(request, 'id')
    user_id = httputils.post(request, 'user_id')
    cus_id = httputils.post(request, 'cus_id')
    if not utils.is_num(id): id = 0
    if not utils.is_num(user_id): user_id = 0
    if not utils.is_num(cus_id): cus_id = 0
    rst = medical_answer_manage.delete(id, user_id, cus_id)
    if rst:
        success = 1
        msg = '成功'
    else:
        success = 0
        msg = '失败'
    return render_to_response('yiliao/medical_answer/delete.xml', {'success':success, 'msg':msg}, mimetype="application/xhtml+xml")
